<?php
/**
 * @version 0.8.3 2010-10-07
 * @package Joomla
 * @subpackage LeagueResults
 * @copyright (C)  2008, 2009, 2010 Henryk Drozd
 * @license GNU/GPL, see LICENSE.php
 * LeagueResults is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License 2
 * as published by the Free Software Foundation.

 * LeagueResults is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 */

// Check to ensure this file is included in Joomla!
defined('_JEXEC') or die('Restricted access');

jimport('joomla.application.component.model');

// Round from lr_fixtures
class lrModelTeamfixtures extends JModel
{
	var $_id = null;
	var $_team = null;
	
	
	function __construct()
	{
	parent::__construct();
	$_id = JRequest::getVar ('id', 0);
	$this->_id = $_id;
	$_team = JRequest::getVar ('team', 0);
	$this->_team_id = $_team;
	}
	
	
	function getList()
	{
	if (!$this->_team)
		{
		$query = "SELECT  f.*, s.name, s.year, matchdate, 
			 			ht.tablename AS hteam, vt.tablename AS vteam,
			 			ht.name AS hteamfullname, vt.name AS vteamfullname,
			 			ht.tbadge AS htbadge, vt.tbadge AS vtbadge,
			 			hc.url AS hurl, vc.url AS vurl,
			 			ht.club_id AS hclub_id, vt.club_id AS vclub_id
					FROM #__lr_fixtures AS f
					JOIN #__lr_teams AS ht ON f.hteam_id = ht.id				
					JOIN #__lr_teams AS vt ON f.vteam_id = vt.id
					JOIN #__lr_clubs AS hc ON ht.club_id = hc.id				
					JOIN #__lr_clubs AS vc ON vt.club_id = vc.id									
					JOIN #__lr_leagueseasons AS s ON f.leagueseasons_id = s.id
					WHERE ((f.hteam_id = '".$this->_team_id."')
							OR (f.vteam_id = '".$this->_team_id."'))
						AND  (s.id = '".$this->_id."')
					ORDER BY f.matchdate, f.matchtime, hteam";
		
				
				
		$this->_team = $this->_getList($query, 0, 0);
		}

	return $this->_team;
	}
}
?>